var shdIndex = new function () {

    /**
     * 初始化
     */
    function init() {
        initWidth();
        initFooter();
        initServer();
        initLeft();
        initInfo();
        initMessage();
        initLczx();
        $(window).resize(function(){initWidth();})
    }

    function initWidth() {
        var width = $(window).width();
        $("#right").width(width - 60);
        $("#contentSub,.mainDiv,#foot,.linkMoreInfo,.kdyfwDiv,.dyDiv,.kdyDiv").width(width-100);
        var leftWidth = parseInt($("#contentLeft").width(),10);
        $("#contentRight").width(width-110-leftWidth);
        $("#lbl,#bl").width((leftWidth-11)/2);
        $("#lbr").width(leftWidth-10-parseInt($("#lbl").width(),10));
        $("#rtl,#rtr,#rbl,#rbr").width((width-120-leftWidth)/2);
        $("#bc,#br").width((width-120-parseInt($("#bl").width(),10))/2);
        $("#bc").css("right",$("#br").width()+10);
    }

    function initFooter(){
        $.get("/s/lk/g", function (data) {
            var htmlXn = "<ul>";
            var countXn = 0;
            var htmlXw = "<ul>";
            var countXw = 0;
            $.each($.parseJSON(data), function (i, item) {
                if (item.type == 1) {
                    if (item.lev == 2) {
                        htmlXn += "<li><a href='" + item.link + "' target='_blank'>" + item.name + "</a></li>";
                    } else {
                        htmlXn += "<li>" + item.name + "</li>";
                    }
                    countXn++;
                    if (countXn % 13 == 0) {
                        htmlXn += "</ul><ul>";
                    }
                }
                if (item.type == 0) {
                    if (item.lev == 2) {
                        htmlXw += "<li><a href='" + item.link + "' target='_blank'>" + item.name + "</a></li>";
                    } else {
                        htmlXw += "<li>" + item.name + "</li>";
                    }
                    countXw++;
                    if (countXw % 13 == 0) {
                        htmlXw += "</ul><ul>";
                    }
                }
            });
            var cXn = countXn % 10 == 0 ? parseInt(countXn / 13, 10) : parseInt(countXn / 13 + 1, 10);
            var cXw = countXw % 10 == 0 ? parseInt(countXw / 13, 10) : parseInt(countXw / 13 + 1, 10);
            var width_xn = countXn % 10 == 0 ? (parseInt(countXn / 13, 10) * 295) : (parseInt(countXn / 13 + 1, 10) * 295);
            var width_xw = countXw % 10 == 0 ? (parseInt(countXw / 13, 10) * 295) : (parseInt(countXw / 13 + 1, 10) * 295);
            $("#moreInLinkDiv .lineSubDiv").html(htmlXn + "</ul><div style='clear:both'></div>");
            $("#moreOutLinkDiv .lineSubDiv").html(htmlXw + "</ul><div style='clear:both'></div>");
            /**
             * ����
             */
            $(".turnLeft").click(function () {
                var $lineSubDiv = $(this).siblings(".linkContentDiv").find(".lineSubDiv");
                var left = parseInt($lineSubDiv.css("left"), 10);
                if (left != 0) {
                    $lineSubDiv.css("left", left + 295);
                }
            });
            /**
             * ���ҷ�
             */
            $(".turnRight").click(function () {
                var $lineSubDiv = $(this).siblings(".linkContentDiv").find(".lineSubDiv");
                var left = parseInt($lineSubDiv.css("left"), 10);
                if ($lineSubDiv.width() + left > 295 * 3) {
                    $lineSubDiv.css("left", left - 295);
                }
            });
        });
        $("#foot span").hover(function(){
            $(this).find("img").attr("src","/resources/images/shd/icon_sanjiao-a.png");
            $("#"+$(this).attr("o")).css("visibility","visible");
        },function(){
            $(this).find("img").attr("src","/resources/images/shd/icon_sanjiao.jpg");
            $("#"+$(this).attr("o")).css("visibility","hidden");
        })
    }

    function initServer(){
        $(".fwcontent li").hover(function(){
            $(this).find(".fwbutton").show().css("left",(parseInt($(this).width(),10)-96)/2);
            $(this).find(".fwnr,.fwmc").css("visibility","hidden");
        },function(){
            $(this).find(".fwbutton").hide();
            $(this).find(".fwnr,.fwmc").css("visibility","visible");
        });
    }

    function initLeft(){
        var choosed = $("#choosed").val();
        if(choosed!='undefind' && choosed!=null && choosed!=''){
            $("#left li.choosed").removeClass("choosed");
            $("#left li:eq("+choosed+"),#left .leftPopup  li:eq("+choosed+")").addClass("choosed");
        }
        $("#left").hover(function(){
            $(".leftPopup").show("fast");
        },function(){
            $(".leftPopup").hide("fast");
        })
    }

    function initInfo(){
        $("#head .info").hover(function(){
            $(".headMenu").show();
        },function(){
            $(".headMenu").hide();
        });
    }

    function initMessage(){
        $("#head .more").hover(function(){
            $("#unreadMessage").show();
        },function(){
            $("#unreadMessage").hide();
        });
    }

    function initLczx(){
        if($("#bc").find("li").length>7){
            $("#bc .moreB").show();
            $("#bc .moreB").click(function(){
                $("#bc .contentB").css("overflow","auto");
            })
        }else{
            $("#bc .moreB").hide();
        }
    }

    return {
        init: init
    }
}();


$(function () {
    shdIndex.init();
});